package controller;

import dao.student.StudentDao2;
import domain.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MyBatisTest {
    public static void main(String[] args) throws IOException {
        InputStream inputStream= Resources.getResourceAsStream("mybatisconfig.xml");
        SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession=sqlSessionFactory.openSession();
        StudentDao2 studentDao2=sqlSession.getMapper(StudentDao2.class);
//        List<Student> students=studentDao2.queryAllStudent();
//        for(Integer sIndex=0;sIndex<students.size();sIndex++)
//        {
//            System.out.println(students.get(sIndex).toString());
//        }
        Student student = studentDao2.querytudentByJszh("1006");
        if(student!=null)
        {
            System.out.println(student.toString());
        }
        else {
            System.out.println("没有");
        }

        List<Student> studentList=studentDao2.queryStudentByBookName("计算机网络");
        if(studentList.size()>0)
        {
            for(Integer sNum=0;sNum<studentList.size();sNum++)
            {
                System.out.println(studentList.get(sNum).toString());
            }
        }
    }
}
